import instance from "../utils/request";

export function getAttractionInfo(id) {
    return instance({
        url: `/Attraction/${id}`,
        method: 'get',
    }).then(res => {
        return res;
    }).catch(err => {
        console.log(err);
    })
}

export function getAttractionByRegion(regionId, pageNumber, pageSize) {
    return instance({
        url: `/Attraction/region/${regionId}`,
        method: 'get',
        params: {
            pageNumber: pageNumber,
            pageSize: pageSize
        }
    }).then(res => {
        return res;
    }).catch(err => {
        console.log(err);
    })
}

export function searchAttraction(pageNumber, pageSize, query) {
    return instance({
        url: '/Attraction/search',
        method: 'get',
        params: {
            pageNumber: pageNumber,
            pageSize: pageSize,
            query: query
        }
    }).then(res => {
        return res;
    }).catch(err => {
        console.log(err);
    })
}

export function getAttractionByRating(pageNumber, pageSize, regionId = null) {
    const url = regionId ?
        `/Attraction/rating/${regionId}` :
        '/Attraction/rating'

    return instance({
        url,
        method: 'get',
        params: {
            pageNumber,
            pageSize,
        }
    }).then(res => {
        return res;
    }).catch(err => {
        console.log(err);
    })
}

export function getAttractionBySelectCount(pageNumber, pageSize, regionId = null) {
    const url = regionId ?
        `/Attraction/selectCount/${regionId}` :
        '/Attraction/selectCount'

    return instance({
        url,
        method: 'get',
        params: {
            pageNumber,
            pageSize,
        }
    }).then(res => {
        return res;
    }).catch(err => {
        console.log(err);
    })
}

export function getAttractionByHot(pageNumber, pageSize, regionId = null) {
    const url = regionId ?
        `/Attraction/hot/${regionId}` :
        '/Attraction/hot'

    return instance({
        url,
        method: 'get',
        params: {
            pageNumber,
            pageSize,
        }
    }).then(res => {
        return res;
    }).catch(err => {
        console.log(err);
    })
}

export function getAttractionByDistance(pageNumber,pageSize,latitude,longitude){
    return instance({
        url:'/Attraction/distance',
        method:'get',
        params:{
            pageNumber:pageNumber,
            pageSize:pageSize,
            latitude:latitude,
            longitude:longitude
        }
    }).then(res =>{
        return res;
    }).catch(err =>{
        console.log(err);
    })
}

export function likeAttraction(userId, attractionId) {
    return instance({
        url: '/Attraction/likeAttraction',
        method: 'post',
        params: {
            userId: userId,
            attractionId: attractionId
        }
    }).then(res => {
        return res;
    }).catch(err => {
        console.log(err);
    })
}

export function createAttractionComment(comment) {
    return instance({
        url: '/Attraction/createComment',
        method: 'post',
        data: comment
    }).then(res => {
        return res;
    }).catch(err => {
        console.log(err);
    })
}


export function deleteAttractionComment(commentId) {
    return instance({
        url: '/Attraction/deleteComment',
        method: 'delete',
        params: {
            commentId: commentId
        }
    }).then(res => {
        return res;
    }).catch(err => {
        console.log(err);
    })
}

export function getAttractionComments(attractionId, pageNumber, pageSize) {
    return instance({
        url: '/Attraction/getComments',
        method: 'get',
        params: {
            attractionId: attractionId,
            pageNumber: pageNumber,
            pageSize: pageSize
        }
    }).then(res => {
        return res;
    }).catch(err => {
        console.log(err);
    })
}

export function uploadCommentImage(userId, file) {
    return instance({
        url: '/Attraction/uploadCommentImage',
        method: 'post',
        params: {
            userId: userId
        },
        data: file
    }).then(res => {
        return res;
    }).catch(err => {
        console.log(err);
    })
}

export function deleteCommentImage(imageUrl) {
    return instance({
        url: '/Attraction/deleteCommentImage',
        method: 'delete',
        params: {
            imageUrl: imageUrl
        }
    }).then(res => {
        return res;
    }).catch(err => {
        console.log(err);
    })
}

export function addLikeComment(userId, commentId) {
    return instance({
        url: '/Attraction/likeComment',
        method: 'post',
        params: {
            userId: userId,
            commentId: commentId
        }
    }).then(res => {
        return res;
    }).catch(err => {
        console.log(err);
    })
}